﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Home.Master" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Import Namespace="WebHoiChoMuaBan.Models" %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Helpers" %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Utility" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleHolder" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="HeadHolder" runat="server">
    <script type="text/javascript">
    $(document).ready(function () {
       $('#paging_container').pajinate({
	     items_per_page: 9,
        nav_panel_id: '.page_navigation',
          abort_on_small_lists: true,
        nav_label_first: 'First',
        nav_label_last: 'Last',
        nav_label_prev: 'Trang trước',
        nav_label_next: 'Trang sau',
	});
    });
    </script>
    <script type="text/javascript">
    $(document).ready(function () {
       $('#paging_container_older').pajinate({
	     items_per_page: 9,
        nav_panel_id: '.page_navigation_older',
          abort_on_small_lists: true,
        nav_label_first: 'First',
        nav_label_last: 'Last',
        nav_label_prev: 'Trang trước',
        nav_label_next: 'Trang sau',
	});
    });
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ListMenuHeader" runat="server">
  <div class="hoicho_group_product">
        <div class="hoicho_header_feature">
            <ul style="position:relative">
                <%
                    NewsProductHelper nProHelper = new NewsProductHelper();
                    string bold = "style='font-weight: bold'";
                    PageType curPage = (PageType)ViewData["CurrentPage"];
                    Category curCate = (Category)ViewData["CurrentCategory"];
                    //int needSell = (int)ViewData["NeedSell"];
                    int needSell = 0;
                    int provinceId = (int)ViewData["ProvinceId"];

                    List<Category> cate = (List<Category>)ViewData["Categories"];
                    int i;
                    foreach (Category c in cate)
                    {
                        bool isCurrent = curCate != null &&
                                            ((curCate.ParentCategory != null && c.CateId == curCate.ParentCategory.CateId) ||
                                             c.CateId == curCate.CateId);
                        Response.Write(string.Format("<li class='{0}'><a href='{1}?pid={2}&cid={3}&p={4}&need={5}&prvid={6}'>{7}</a>",
                                                    (isCurrent ? "selected_menu hover" : "hover"),
                                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                    curPage.PageId,
                                                    c.CateId,
                                                    1,
                                                    needSell,
                                                    provinceId,
                                                    c.CateName));
                        List<Category> subCate = nProHelper.getSubCate(c.CateId);
                        Response.Write("<div id='submenu'><span style='position: absolute; top: 30px;'><ul class='hidden' style='z-index:1000;'>");
                        foreach (Category sc in subCate)
                        {
                            Response.Write(string.Format("<li class='{0}'><a href='{1}?pid={2}&cid={3}&p={4}&need={5}&prvid={6}'>{7}</a></li>",
                                                           (""),
                                                           Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                           curPage.PageId,
                                                           sc.CateId,
                                                           1,
                                                           needSell,
                                                           provinceId,
                                                           sc.CateName));
                        }
                        Response.Write("</ul></span><div></li>");
                    }
                %>
            </ul>
            <%--     <%
                foreach (Category sc in cate)
                {
                    List<Category> subCate = nProHelper.getSubCate(sc.CateId);
                    Response.Write("<div>");
                    Response.Write(string.Format("<li class='{0}'><a href='{1}?pid={2}&cid={3}&p={4}&need={5}&prvid={6}'>{7}</a></li>",
                                                   ( string.Empty),
                                                   Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                   curPage.PageId,
                                                   sc.CateId,
                                                   1,
                                                   needSell,
                                                   provinceId,
                                                   sc.CateName));
                    Response.Write("</div>");
                }
                   %>--%>
        </div>
        <div class="hoicho_feature_content">
            <%--     <div class="private_breakpage_replycoment col_left reset_margin">
                <%
                    Response.Write(string.Format("<a {0} href='{2}?pid={3}&cid={4}&p={5}&need={6}&prvid={8}'>Cần bán</a> | <a {1} href='{2}?pid={3}&cid={4}&p={5}&need={7}&prvid={8}'>Cần mua</a>",
                                                    (needSell == NewsProductHelper.NEED_SELL ? bold : string.Empty),
                                                    (needSell == NewsProductHelper.NEED_BUY ? bold : string.Empty),
                                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                    curPage.PageId,
                                                    (curCate != null ? curCate.CateId : 0),
                                                    1,
                                                    NewsProductHelper.NEED_SELL,
                                                    NewsProductHelper.NEED_BUY,
                                                    provinceId));
                %>
            </div>--%>
            <%--       <div class="hoicho_select_province col_right">
                <span class="hoicho_margin_right">
                    <%
                        StringBuilder provLinks = new StringBuilder();
                        provLinks.Append("<a {0} href='{4}?pid={5}&cid={6}&p={7}&need={8}&prvid=2'>Hà Nội</a> | ");
                        provLinks.Append("<a {1} href='{4}?pid={5}&cid={6}&p={7}&need={8}&prvid=6'>Hải Phòng</a> | ");
                        provLinks.Append("<a {2} href='{4}?pid={5}&cid={6}&p={7}&need={8}&prvid=3'>Hồ Chí Minh</a> | ");
                        provLinks.Append("<a {3} href='{4}?pid={5}&cid={6}&p={7}&need={8}&prvid=5'>Đà Nẵng</a> |");
                        Response.Write(string.Format(provLinks.ToString(),
                                                (provinceId == 2 ? bold : string.Empty), // {0}
                                                (provinceId == 6 ? bold : string.Empty), // {1}
                                                (provinceId == 3 ? bold : string.Empty), // {2}
                                                (provinceId == 5 ? bold : string.Empty), // {3}
                                                Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                curPage.PageId,
                                                (curCate != null ? curCate.CateId : 0),
                                                1,
                                                needSell // buy or sell
                                                ));
                    %>
                </span><span>
                    <select id="cbbProvince" class="hoicho_input_select_province">
                        <%
                            string selected = "selected='selected'";
                            List<Province> provinces = (List<Province>)ViewData["Provinces"];
                            foreach (Province pr in provinces)
                            {
                                Response.Write(string.Format("<option value='{0}' {2}>{1}</option>",
                                                            pr.ProvId,
                                                            pr.ProvName,
                                                            (provinceId == pr.ProvId ? selected : string.Empty)
                                                            ));
                            }
                        %>
                    </select>
                    <script type="text/javascript">
                            jQuery("#cbbProvince").change(function () {
                                location.href=<%=string.Format("'{0}?pid={1}&cid={2}&p={3}&need={4}'",
                                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                    curPage.PageId,
                                                    (curCate != null ? curCate.CateId : 0),
                                                    1,
                                                    needSell // buy or sell
                                                    ) %> + '&prvid=' + jQuery(this).val();
                            });
                    </script>
                </span>
            </div>--%>
        </div>
        <%
            //int j = 1;
            //foreach (Category c in cate)
            {
                //Response.Write(string.Format("<div id='cate_{1}' class='hoicho_group_listmenu_fation page_{2}' {0}>", (j>1 ? "style='display:none'" : string.Empty), c.CateId, c.PageId));
                Response.Write("<div>");
                //j++;

                if (curCate != null)
                {
                    List<CategoryHelper.SubCategory> subcategories = null;
                    if (curCate.SubCategories != null && curCate.SubCategories.Count > 0)
                    {
                        //Số dòng mỗi cột
                        subcategories = (from sub in curCate.SubCategories
                                         select new CategoryHelper.SubCategory
                                         {
                                             id = sub.CateId,
                                             name = sub.CateName
                                         }).ToList();
                    }
                    else if (curCate.ParentCategory != null)
                    {
                        subcategories = (from sub in curCate.ParentCategory.SubCategories
                                         select new CategoryHelper.SubCategory
                                         {
                                             id = sub.CateId,
                                             name = sub.CateName
                                         }).ToList();
                    }

                    if (subcategories != null)
                    {
                        int perRow = (int)Math.Ceiling((double)subcategories.Count / 4);

                        //4 cột subcategories
                        for (i = 0; i < 4; i++)
                        {
                            var subCate = (from sub in subcategories select sub).Skip(perRow * i).Take(perRow);
                            if (subCate != null)
                            {
                                Response.Write("<div class='private_menu_list_product'><ul>");
                                foreach (var s in subCate)
                                    Response.Write(string.Format("<li><a href='{0}?pid={1}&cid={2}&p={3}' style='font-weight: {4}'>{5}</a></li>",
                                                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                                    curPage.PageId,
                                                                    s.id,
                                                                    1,
                                                                    ((curCate != null && curCate.CateId == s.id) ? "bold" : "normal"),
                                                                    s.name));
                                Response.Write("</ul></div>");
                            }
                        }
                    }
                }
                Response.Write("</div>");
            }
        %>
    </div>
    <script type="text/javascript">
        $(".hoicho_group_product li.hover").mouseover(function () {
            $this = $(this).find("ul.hidden");
            $this.removeClass("hidden");
        });
        $(".hoicho_group_product li.hover").mouseout(function () {
            $this = $(this).find("ul");
            $this.addClass("hidden");
        });
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="MainContentHolder" runat="server">
    <script type="text/javascript">
        var lastReplyHidden = null;
        jQuery(document).ready(function () {
            RegisterReplyButton();
        });
    </script>
    <%--begin detail news--%>
    <div class="left">
        <%
            NewsProduct news = (NewsProduct)ViewData["News"];
            Response.Write(string.Format("<div class='hoicho_new_detail_title'>{0}</div>", news.NProTitle));
            Response.Write(string.Format("<div class='hoicho_new_detail_content'>{0}</div>", news.NProContent));
        %>
        <div>
            <div style="float:right" class="private_logo_share col_left hoicho_margin_right">
               <%--   <div class="private_logo_share">--%>
                            <!-- AddToAny BEGIN -->
                            <div class="a2a_kit a2a_default_style">
                                <a class="a2a_dd" href="http://www.addtoany.com/share_save?linkurl=hoichomuaban.com&amp;linkname=Hoi%20Cho%20Mua%20Ban">
                                    Chia sẻ</a> <span class="a2a_divider"></span><a class="a2a_button_facebook">
                                </a><a class="a2a_button_twitter"></a><a class="a2a_button_google_bookmarks"></a>
                                <a class="a2a_button_digg"></a>
                                <!-- AddToAny END -->
                            <%--</div>--%>
                        </div>
            </div>
        </div>
        <div class="clear">
        </div>
        <div class="private_coment_group">
            <div class="private_coment_text">
                <a name="comments">Bình luận</a>
            </div>
            <% if (Session["MemId"] != null)
               { %>
            <form action="<%=Url.Action("AddComment", "NewsProduct") %>" method="post" class="private_content_comment">
            <input type="hidden" value="<%=news.NProId %>" name="newsId" id="newsId" />
            <div class="private_menu_topmenu">
                <textarea class="input_full" rows="5" cols="45" id="txtComment" style="width:500px" name="txtComment"></textarea>
            </div>
          <div class="private_post_text">
            <div style="background-color:White;margin-top:5px">
                    <span class="private_font_bold">Chọn icon: </span>
                    <% ChatHelper chat = new ChatHelper();
                       List<ChatEmotionDetail> icons = chat.getEmotionPath();
                       foreach (ChatEmotionDetail icon in icons)
                       {
                           Response.Write("<img align='middle' onclick='MemchatIconClick(this)' src='" + icon.path + "' id='" + icon.notation + "' width='40px' height='40px' />");

                       }
                    %>
                    <script type="text/javascript">
                        function MemchatIconClick(obj) {
                            $this = document.getElementById("txtComment");
                            $this.value += obj.id;
                        }
                    </script>
                </div>
                <div style="margin-left:250px;">
                    <input type="submit" style="width: 60px;" id="" value="Gửi" class="private_bt_submit_news_disable" />
                </div>
            </div>
            </form>
            <% } %>
        </div>
        <form action="<%=Url.Action("AddComment", "NewsProduct") %>" method="post" class="private_content_comment"
        style="margin-left: auto; display: none" id="frmReplyTo">
        <input type="hidden" value="" name="replyTo" id="replyTo" />
         <input type="button" value="đóng" style="margin-left:250px" class="btnReplyClose_<%=news.NProId %>" onclick="CloseRegisterReplyButton(<%=news.NProId %>)"/>
        <input type="hidden" value="<%=news.NProId %>" name="newsId" id="Hidden1" />
        <div class="private_menu_topmenu">
            <textarea class="input_full" rows="5" cols="45" id="ChatArea" style="width:300px;" name="txtComment"></textarea>
        </div>
         <div class="private_post_text">
        <div style="margin-top:5px;background-color:white">
                <span class="private_font_bold">Chọn icon: </span>
                <% ChatHelper nchat = new ChatHelper();
                   List<ChatEmotionDetail> nicons = nchat.getEmotionPath();
                   foreach (ChatEmotionDetail icon in nicons)
                   {
                       Response.Write("<img align='middle' onclick='chatIconClick(this)' src='" + icon.path + "' id='" + icon.notation + "' width='40px' height='40px' />");

                   }
                %>
                <script type="text/javascript">
                    function chatIconClick(obj) {
                        $this = document.getElementById("ChatArea");
                        $this.value += obj.id;
                    }
                </script>
            </div>
            <div style="margin-left:200px;">
                <input type="submit" style="width: 60px;" id="Submit1" value="Gửi" class="private_bt_submit_news_disable" />
            </div>
        </div>
        </form>
        <div class="clear">
        </div>
        <div id="paging_container" class="container">
            <div class="page_navigation private_breakpage" style="text-align: right">
            </div>
            <ul class="content">
                <%
                    NewsProductHelper productHelper = new NewsProductHelper();
                    //List<NewsProductComment> comments = (from n in news.NewsProductComments
                    //                                     where n.ComIdReply == null
                    //                                     orderby n.ComDate descending
                    //                                     select n).ToList();
                    List<NewsProductComment> comments = productHelper.getListCommentByProductId(news.NProId);
                    foreach (var com in comments)
                    {
                %>
                <!-- Content comment -->
                <li>
                    <div class="private_content_mg_thumb">
                        <div class="private_comment_repply">
                            <div class="private_comment_user">
                                <div class="private_img_post_bt">
                                    <img class="private_img_post" alt="" width="50" height="50" src="/../Content/Images/Upload/<%=com.Member.MemAvatar %>" />
                                </div>
                                <div class="private_messages_text">
                                    <div class="commentId" style="display: none">
                                        <%=com.ComId %></div>
                                    <p>
                                        <span class="private_text_title">
                                            <%=com.Member.MemUsername %></span> &nbsp;&nbsp;<span class="private_timer_repply"><%=com.ComDate.ToString("HH:mm | dd.MM.yyyy") %></span></p>
                                    <p>
                                        <%=com.ComContent %>
                                    </p>
                                    <%
                                    if (Session["MemId"] != null)
                                    { %>
                                    <div class="private_link_repply">
                                    <a href="#" class="btnReply">Trả lời</a></div>
                                    <%}
                                    else{
                                        Response.Write("<div class='private_link_repply'>");
                                        Response.Write("Đăng nhập để bình luận");
                                        Response.Write("</div>");
                                        }%>
                                </div>
                            </div>
                            <div class="clear">
                            </div>
                            <%
//List<NewsProductComment> replies = (from r in com.NewsProductReply
//                                    orderby r.ComDate descending
//                                    select r).ToList();

List<NewsProductComment> replies = productHelper.getListCommentReplyByCommentId(com.ComId);
foreach (NewsProductComment r in replies)
{
                            %>
                            <div class="private_admin_reply">
                                <div class="private_arrowtop_adminreply">
                                </div>
                                <div class="private_content_adminreply">
                                    <div class="private_img_post_bt">
                                        <img class="private_img_post" alt="" width="50" height="50" src="/../Content/Images/Upload/<%=r.Member.MemAvatar %>" />
                                    </div>
                                    <div class="private_messages_text">
                                        <p>
                                            <span class="private_user">
                                                <%=r.Member.MemUsername %></span>&nbsp;&nbsp; <span class="private_timer_repply">
                                                    <%=r.ComDate.ToString("HH:mm | dd.MM.yyyy") %></span></p>
                                        <p>
                                            <%=r.ComContent %>
                                        </p>
                                    </div>
                                </div>
                            </div>
                            <% } %>
                        </div>
                        <hr class="private_color_hr" />
                    </div>
                    <!-- endContent comment -->
                </li>
                <% } %>
            </ul>
            <div class="page_navigation private_breakpage" style="text-align: right">
            </div>
        </div>
        <div>
            <p class="hoicho_new_detail_relate_title">
                Tin mới hơn.....................................................................................................</p>
            <%
                List<NewsProduct> nNews = productHelper.getNewerNews(news.NProId);
                foreach (NewsProduct n in nNews)
                {
                    Response.Write(string.Format("<div class='hoicho_new_detail_relate'><a href='{0}?prid={1}'><img style='margin-right:3px' src='/../Content/Images/star.png' height='14px' width='14px'/>{2}</a></div>", Url.Action("Detail", "NewsProduct", new { productTitle = MiscUtil.EscapeString(n.NProTitle) }), n.NProId, n.NProTitle));
                }
            %>
        </div>
        <div>
            <p class="hoicho_new_detail_relate_title">
                Tin cũ hơn........................................................................................................</p>
            <div id="paging_container_older" class="container">
                <ul class="content">
                    <%
                        List<NewsProduct> oNews = productHelper.getOlderNews(news.NProId);
                        foreach (NewsProduct n in oNews)
                        {
                            Response.Write("<li>");
                            Response.Write(string.Format("<div class='hoicho_new_detail_relate'><a href='{0}?prid={1}'><img src='/../Content/Images/star.png' align='middle' height='14px' width='14px'/>{2}</a></div>", Url.Action("Detail", "NewsProduct", new { productTitle = MiscUtil.EscapeString(n.NProTitle) }), n.NProId, n.NProTitle));
                            Response.Write("</li>");
                        }
                    %>
                </ul>
                <div class="page_navigation_older private_breakpage" style="text-align: right">
                </div>
            </div>
        </div>
        <div class="hoicho-timepicker" style="margin:3px">
            Các tin đăng ngày:
            <input class="inputDate" style="width:100px;" id="inputDate" />
            <input type="button" id="Button1" class="private_bt_submit_news " data-url='<%:Url.Action("SearchNews", "Home")%>'  value="Xem"/>
            <script type="text/javascript">
                $('.hoicho_button_search_news').click(function () {
                    var $this = $(this);
                    //var radio = document.getElementById("mysearchcat");
                    // var input = radio.getElementsByTagName("input");
                    var spid = 10;
                    //                    for (var i = 0; i < input.length; i++) {
                    //                        if (input[i].checked == true) {
                    //                            spid = input[i].value;
                    //                        }
                    //                    }
                    var data = $this.data("url");

                    data += "?pid=" + spid + "&cid=0&p=1&date="+$('#inputDate').DatePickerGetDate("dd/mm/yyyy") ;
                    window.location = data;
                });
            </script>
            <script type="text/javascript">
                function currentDate() {
                    var currentDate = new Date();
                    var day = currentDate.getDate();
                    var month = currentDate.getMonth() + 1;
                    var year = currentDate.getFullYear();

                    var docs = document.getElementById("inputDate");
                    docs.value = day + "/" + month + "/" + year;
                }
                currentDate();
                $('#inputDate').DatePicker({
                    format: 'd/m/Y',
                    date: $('#inputDate').val(),
                    current: $('#inputDate').val(),
                    starts: 1,
                    position: 'r',
                    onBeforeShow: function () {
                        $('#inputDate').DatePickerSetDate($('#inputDate').val(), true);
                    },
                    onChange: function (formated, dates) {
                        $('#inputDate').val(formated);
                        // if ($('#closeOnSelect input').attr('checked')) {
                        $('#inputDate').DatePickerHide();
                        //}
                    }
                });
            </script>
        </div>
    </div>
    <div class="right">
        <div class="hoicho_group_product">
            <div class="hoicho_header_feature">
                <ul>
                    <li>
                        <p>
                            Tâm điểm</p>
                    </li>
                </ul>
            </div>
        </div>
        <%
            NewsProductHelper pHelper = new NewsProductHelper();
            List<NewsProduct> poNews = pHelper.getPopularNews();
        %>
        <%
            foreach (NewsProduct pop in poNews)
            {

                Response.Write(string.Format("<div class='hoitro_new_popular'><a href='{0}?prid={1}'>{2}</a></div>", Url.Action("Detail", "NewsProduct", new { productTitle = MiscUtil.EscapeString(pop.NProTitle) }), pop.NProId, pop.NProTitle));

            }
        %>
    </div>
    <div class="clr">
    </div>
    <%--end detail news--%>
</asp:Content>
